<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绘制垂直方向文字</title>
    <style>
        canvas{
            border: 1px solid #333;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="600" height="600"></canvas>
    <script>
        const canvas = document.getElementById('canvas');
        const ctx = canvas.getContext('2d');

        ctx.font = "50px 微软雅黑";
        ctx.fillStyle = "red";
        
        // ctx.textBaseline = "alphabetic";   // 基线对齐
        ctx.textBaseline = "middle";        // 中线对齐
        // ctx.textBaseline = "bottom";        // 底线对齐
        // ctx.textBaseline = "top";           // 顶线对齐

        ctx.fillText("Xx北京真冷", 200,200);  // 文字内容及文字位置
        
        ctx.beginPath();
        ctx.moveTo(0,200);
        ctx.lineTo(600,200);
        ctx.stroke();
    </script>
</body>
</html>